<template>
    <div>
        <div class="signUp">
            <div class="signUp-head">
                <span>用户注册</span>
            </div>
            <el-form :model="registerForm" ref="registerForm" label-width="80px" class="demo-ruleForm" :rules="rules">
                <el-form-item prop="username" label="用户名">
                    <el-input v-model="registerForm.username" placeholder="username"></el-input>
                </el-form-item>
                <el-form-item prop="password" label="密码">
                    <el-input type="password" v-model="registerForm.password" placeholder="password"></el-input>
                </el-form-item>
                <div class="login-btn">
                    <el-button @click="goback(-1)">取消</el-button>
                    <el-button type="primary" @click="SignUp">确定</el-button>
                </div>
            </el-form>
        </div>
    </div>

</template>

<script>

    import {SignUp} from "../api/index";
    import {mixin} from "../mixins";
    import {rules} from "../assets/data/form";


    export default {
        name: "sing-up",
        mixins:[mixin],

        data(){
            return {
                registerForm:{
                    username:'',
                    password:'',

                },
                rules:{}
            }
        },
        created() {
            this.rules=rules;
        },
        methods:{
            SignUp(){
                let params=new URLSearchParams();
                let _this=this;
                params.append('username',this.registerForm.username);
                params.append('password',this.registerForm.password);
                params.append('photo','photo.jpg');
                SignUp(params).then(res =>{

                    console.log(res.data.status)
                    if (res.status===1){
                        _this.notify('注册成功','success');

                    }else {
                        _this.notify('注册error','error');
                        setTimeout(function () {
                            _this.$router.push({path:'/'});
                        },1000);
                    }

                }).catch(err=>{
                    _this.notify('注册失败','error');
                })

            },
            goback(index){
                this.$router.go(index);
            }

        }
    }
</script>

<style lang="scss" scoped>
@import "../assets/css/sign-up";
</style>